Skip to content

centralized logging for BWS and BCN.#4137

Open
tmcollins4 wants to merge 1 commit intobitpay:masterfrom
tmcollins4:add-bitcore-logging-package
Open

centralized logging for BWS and BCN.#4137
tmcollins4 wants to merge 1 commit intobitpay:masterfrom
tmcollins4:add-bitcore-logging-package

Conversation

@tmcollins4
Copy link
Copy Markdown
Contributor

Description

Centralized the duplicated Winston logging logic from bitcore-node (BCN) and bitcore-wallet-service (BWS) into a new shared @bitpay-labs/bitcore-logging package. This eliminates the duplication and gives a single place to evolve logging going forward.

Changelog

  • Added packages/bitcore-logging/ — new shared logging package with createLogger(config) factory, timestamp utilities, Winston format helpers, and Loggify decorators.
  • createLogger({ prefix: 'BCN' | 'BWS' }) reads existing env vars (BCN_LOG_*, BWS_LOG_*) — no configuration changes required.
  • Replaced packages/bitcore-node/src/logger.ts with a thin shim delegating to bitcore-logging.
  • Replaced packages/bitcore-node/src/decorators/Loggify.ts with a thin shim re-exporting from bitcore-logging.
  • Replaced packages/bitcore-wallet-service/src/lib/logger.ts with a thin shim delegating to bitcore-logging.
  • All ~90 files in BCN/BWS that import from their local logger are unchanged — shim pattern preserves existing import paths.
  • Fixed pre-existing padEndpadStart bug in millisecond formatting in formatTimestamp.
  • Removed winston as a direct dependency from BCN and BWS.
  • Added 29 unit tests covering logger factory, transports, formatters, timestamp, and Loggify decorators.

Testing Notes

  • Ran BCN & BWS unit tests
  • Log output verified identical to pre-migration via side-by-side HTTP transport comparison.

Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.

Copy link
Copy Markdown
Collaborator

@kajoseph kajoseph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a few type errors in BWS:

The inferred type of 'logger' cannot be named without a reference to '@bitpay-labs/bitcore-logging/node_modules/winston'. This is likely not portable. A type annotation is necessary.

Removing declaration and declarationMap from BWS's tsconfig.json fixes it. BWS isn't an imported codebase, so we don't need TS to compile .d.ts files anyway.

"name": "@bitpay-labs/bitcore-logging",
"description": "Centralized logging for Bitcore services",
"author": "BitPay Inc",
"version": "11.6.6",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to 11.7.0 to fix the build failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants